<?php
if(!defined('ADMIN')){
	exit('Access Denied');
}
if($_POST['sub']!=''){
    $id=empty($_POST['id'])?0:(int)$_POST['id'];
	unset($_POST['id']);
	unset($_POST['sub']);
    
    
    if(trim($_POST["sname"])==""){
        
        jumpajax('300','店铺名称不能为空!','');
    }
    if(trim($_POST["telephone"])==""){
        
        jumpajax('300','联系电话不能为空!','');
    }
    if(trim($_POST["address"])==""){
        
        jumpajax('300','饭店地址不能为空!','');
    }
    $sname=trim($_POST["sname"]);
    
    if(empty($id)){
        $num=$ezhand->count("shopping3_shop","sname='$sname'");    
    }else{
        $num=$ezhand->count("shopping3_shop","sname='$sname' and id<>".$id);
    }
    if($num>0){
        
        jumpajax('300','店名“'.$sname.'”已存在!','');
    }
    $status=intval($_REQUEST["status"]);
    $p=0;
    //
    
	$data=array('sname'=>trim($_POST["sname"]),
    'thumb'=>trim($_POST["imgs0_fileName"]),
    'description'=>trim($_POST["description"]),
    'createtime'=>time(),
    'address' =>trim($_POST["address"]),
    'telephone' => trim($_POST["telephone"]),
    'status'=>$status,
    'service_starttime'=>trim($_POST["service_starttime"]),
    'service_stoptime'=>trim($_POST["service_stoptime"]),
    );
 	if($id==0){
        $id=$ezhand->insert("shopping3_shop",$data);
		jumpajax('200','名店保存成功','page457','closeCurrent');
	}else{
	    $ezhand->update("shopping3_shop",$data,'id="'.$id.'"');
        
      
		jumpajax('200','名店修改成功','page457','closeCurrent');
	}
}else{
      $timelist=range(0,24);
	$id=empty($_GET['id'])?0:(int)$_GET['id'];
    if($id==0){
	    $row=array();
        $dishes=array();
	}else{
	   
	    $row=$ezhand->select("shopping3_shop",'*','id="'.$id.'"');
        
	}
}
?>